package com.shuoyue.ycgk.ui.mok;

import android.content.Context;
import android.content.Intent;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.base.ListWithPage;
import com.shuoyue.ycgk.entity.Mok;
import com.shuoyue.ycgk.entity.MokType;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MokTypeActivity extends BaseMvpActivity<MokContract.Presenter> implements MokContract.View {
    MokTypeAdapter adapter;
    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.refreshlayout)
    SmartRefreshLayout refreshlayout;

    public static void start(Context source) {
        source.startActivity(new Intent(source, MokTypeActivity.class));
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mok_type;
    }

    @Override
    protected void initView() {
        pageTitle.setText("模考");
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 12)));
        adapter = new MokTypeAdapter(null);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemChildClickListener((adapter, view, position) -> {
            MokType mok = (MokType) adapter.getItem(position);
//            MokListActivity.start(mContext, mok);
        });
        refreshlayout.setEnableLoadMore(false);
        refreshlayout.setOnRefreshListener(refreshLayout -> {
            mPresenter.getMokType();
            refreshLayout.finishRefresh(2000);
        });
        registEmptyView(adapter);
    }

    @Override
    public void initData() {
        mPresenter = new MokContract.Presenter();
        mPresenter.attachView(this);
        mPresenter.getMokType();
    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void setMokList(List<Mok> list) {

    }

    @Override
    public void setMokTypeList(List<MokType> mokList) {
        adapter.resetData(mokList);
        refreshlayout.finishRefresh();
        refreshlayout.finishLoadMore();
    }
}
